<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子9-JS进阶（三）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 例子9

                    var url1 = 'https://hq.tigerbrokers.com/fundamental/finance_calendar/getType/2017-02-26/2017-06-10';
                    var url2 = 'https://hq.tigerbrokers.com/fundamental/finance_calendar/getType/2017-03-26/2017-06-10';

                    function getJSON(url) {
                        return new Promise(function(resolve, reject) {
                            var XHR = new XMLHttpRequest();
                            XHR.open('GET', url, true);
                            XHR.send();

                            XHR.onreadystatechange = function() {
                                if (XHR.readyState == 4) {
                                    if (XHR.status == 200) {
                                        try {
                                            var response = JSON.parse(XHR.responseText);
                                            resolve(response);
                                        } catch (e) {
                                            reject(e);
                                        }
                                    } else {
                                        reject(new Error(XHR.statusText));
                                    }
                                }
                            }
                        })
                    }

                    function renderAll() {
                        return Promise.all([getJSON(url1), getJSON(url2)]);
                    }

                    renderAll().then(function(value) {
                        console.log(value);
                    })
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/9.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>